<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .box {
            width: 340px;
            height: 500px;
            margin: 50px auto;
            border: 1px solid #eee;
            padding: 10px;
        }

        .hang input {
            width: 260px;
            height: 30px;
            background-color: #eee;
            border: 0;
            padding: 0 10px;
            margin-right: 10px;
        }

        .hang span {
            color: darkcyan;
            cursor: pointer;
        }

        .hang1 {
            margin-top: 10px;
        }

        .hang1 button {
            border: 0;
            padding: 8px;
            margin-right: 10px;
            border-radius: 5px;
            background-color: darkcyan;
            color: white;
        }

        .hang1 button:nth-child(3) {
            background-color: red;
        }

        .zi {
            font-weight: bold;
            padding: 20px 0;
        }

        .zhen {
            height: 40px;
            background-color: red;
            color: white;
            line-height: 40px;
            margin-bottom: 10px;
        }

        .zhen.active {
            background-color: darkcyan;
        }

        .kong {
            float: left;
            margin: 0 10px;
        }

        .id {
            float: left;
            margin: 0 10px;
        }

        .name {
            float: left;
            margin: 0 10px;
        }

        .tai {
            float: right;
            margin: 0 10px;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="hang">
            <input type="text" placeholder="输入任务名称" v-model="zhi"><span @click="add">新增</span>
        </div>
        <div class="hang1">
            <button>全部任务（{{renwu}}）</button>
            <button>已完成（{{wancheng}}）</button>
            <button>未完成（{{weiwan}}）</button>
        </div>
        <div class="zi">任务列表</div>
        <div :class="{zhen:true,active:item.status}" v-for="(item,index) in list" :key="index">
            <div class="kong"><input type="checkbox" @click="tai(item)"></div>
            <div class="id">{{item.id}}</div>
            <div class="name">{{item.name}}</div>
            <div class="tai">删除</div>
        </div>
    </div>
</body>

</html>
<script src="./vue-2.5.21.js"></script>
<script>
    var v = new Vue({
        el: '.box',
        data: {
            zhi: '',
            list: []
        },
        methods: {
            add() {
                if (this.zhi) {
                    var obj = { id: this.list.length + 1, name: this.zhi, status: false }
                    this.list.push(obj)
                    this.zhi = ''
                }
            },
            tai(item) {
                item.status = !item.status
            }
        },
        computed: {
            renwu() {
                return this.list.length
            },
            wancheng(){
                return this.list.filter((item)=>{return item.status}).length
            },
            weiwan(){
                return this.list.length-this.wancheng
            }
        }
    })
</script>